package cn.northsea.mapper;

import cn.northsea.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleMapper {


    @Select("SELECT r.*\n" +
            "FROM rms_user u INNER JOIN rms_user_role ur \n" +
            "ON u.id=ur.uid INNER JOIN rms_role r\n" +
            "ON ur.rid=r.rid WHERE u.id=#{value}")
    List<Role> findRolesByUid(Integer id);


//    List<Role> findAll(@Param("likename")String likename);

    @Select("select r.*\n" +
            "from erp_user_role ur inner join erp_role r\n" +
            "on ur.role_id = r.role_id\n" +
            "where ur.user_id = #{value}")
    List<Role> findRoleByUid(Integer id);


    @Delete("delete from erp_user_role where user_id = #{value}")
    void delRole(Integer userId);

    void allocationRole(@Param("rids") List<Integer> rids, @Param("userId") Integer userId);

    @Select("select * from erp_role")
    List<Role> findAll2();


    List<Role> findAll(String likename);

    @Select("select * from erp_role where role_name = #{value}")
    Role checkRoleName(String roleName);


    @Insert("insert into erp_role values (null,#{roleName},#{roleDesc},#{createAt},0)")
    void addRole(Role role);


    void delRole2(Integer[] ids);
}
